home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group00b.txt / 000114_icon-group-sender_Thu Oct 26 12:49:26 2000.msg < prev    next >
Internet Message Format  |  2001-01-03  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id e9QJnGO01100
  4.     for icon-group-addresses; Thu, 26 Oct 2000 12:49:16 -0700 (MST)
  5. Message-Id: <200010261949.e9QJnGO01100@baskerville.CS.Arizona.EDU>
  6. Date: Thu, 26 Oct 2000 10:05:24 -0700 (PDT)
  7. From: Shamim Mohamed <shamim@drones.com>
  8. To: Bob Ardler <ardler@argonet.co.uk>
  9. Cc: icon-group@cs.arizona.edu
  10. Subject: Re: Yet another Newbie question....
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12. Status: RO
  13. Content-Length: 1291
  14.  
  15.  >> line ? while tab(upto(&letters)) do move(1)
  16.  
  17.  > Intimidates? Sends you screaming come back awk, come back perl, all
  18.  > is forgiven?
  19.  
  20. No! Don't go back to the dark side!
  21.  
  22. The ? operator sets up a string scanning environment - a string and
  23. position in it. upto(cset) returns the next position (starting from the
  24. current position) that a member of the cset occurs; and tab(i) sets the
  25. position to i.
  26.  
  27. So tab(upto(&letters)) moves the position to the next occurrence of a
  28. letter.
  29.  
  30. move(i) advances the position by i; so move(1) skips over the occurrence 
  31. of the letter just found. tab() is absolute, move() is relative. (tab()
  32. and move() also return the piece of the string they just skipped over.)
  33.  
  34. upto() will fail if it found no more occurrences in the string that are 
  35. in the cset; so the while loop makes the whole thing go and terminate
  36. correctly.
  37.  
  38. There are numerous examples in the books that are in the Icon idiom.
  39. Here's a very common way to find all the words in a line:
  40.  
  41.    line ? while tab(upto(&letters)) do {
  42.       word := tab(many(&letters))
  43.       ... do something interesting with the word....
  44.    }
  45.  
  46. many() is the converse of upto(); it returns the position of the end of
  47. the substring with characters from the cset.
  48.  
  49. The books explain all this much better than I can!
  50.  
  51. -s
  52.